//
//  NoticeVC.m
//  BasePorject_App
//
//  Created by Yutian Duan on 2019/5/27.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "NoticeVC.h"
#import "NoticeListVC.h"

@interface NoticeVC () <LTSimpleScrollViewDelegate>

@property (nonatomic, strong) UIView *headView;
///! 控制器 和 title
@property (nonatomic, copy) NSArray <UIViewController *> *viewControllers;
@property (nonatomic, copy) NSArray <NSString *> *titles;

@property (nonatomic, strong) LTLayout *layout;
@property (nonatomic, strong) LTSimpleManager *managerView;

@end

@implementation NoticeVC

- (NSArray <NSString *> *)titles {
  if (!_titles) {
    _titles = @[YTLocalizedString(@"全部"), YTLocalizedString(@"油咭"), YTLocalizedString(@"产品"), YTLocalizedString(@"系统")];
  }
  return _titles;
}

- (NSArray <UIViewController *> *)viewControllers {
  if (!_viewControllers) {
    _viewControllers = [self setupViewControllers];
  }
  return _viewControllers;
}

- (NSArray <UIViewController *> *)setupViewControllers {
  
  NSMutableArray <UIViewController *> *testVCS = [NSMutableArray arrayWithCapacity:0];
  [self.titles enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    NoticeListVC *testVC = [[NoticeListVC alloc] init];
    [testVCS addObject:testVC];
  }];
  return testVCS.copy;
}

- (UIImageView *)setupHeaderView {
  
  UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * ITEMPRO)];
  headerImageView.clipsToBounds = YES;
  headerImageView.contentMode = UIViewContentModeScaleAspectFill;
  headerImageView.image = [UIImage imageNamed:@"Home_BgImage"];
  
  
  //！
  UILabel *welcomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, headerImageView.yt_centerY - 40, 120, 40)];
  welcomeLabel.text = YTLocalizedString(@"通知");
  welcomeLabel.textColor = [UIColor whiteColor];
  welcomeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
  [headerImageView addSubview:welcomeLabel];
  welcomeLabel.yt_bottom = headerImageView.yt_height/2;
  
  CGFloat logoH = 13;
  if (IS_IPHONE5) {
    logoH = 10;
  }
  //! logo
  UIImageView *logoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, welcomeLabel.yt_bottom, logoH * 14, logoH)];
  logoView.image = [UIImage imageNamed:@"Home_logo"];
  logoView.contentMode = UIViewContentModeScaleAspectFit;
  [headerImageView addSubview:logoView];
  logoView.yt_right = headerImageView.yt_right - 20;

  
  return headerImageView;
}

- (LTSimpleManager *)managerView {
  if (!_managerView) {
    
    _layout = [[LTLayout alloc] init];
    _layout.bottomLineHeight = 2.0;
    _layout.bottomLineCornerRadius = 2.0;
    _layout.titleFont = [UIFont systemFontOfSize:14];
    _layout.isAverage = YES;
    _layout.titleColor = DEF_GRAY;
    _layout.titleSelectColor = RGBCOLOR(1, 1, 1);
    //
    _layout.bottomLineColor = RGBCOLOR(1, 1, 1);
    _layout.sliderWidth = ScreenWidth/4;
    _layout.titleViewBgColor = HEXCOLOR(0xf7f8fc);
    _managerView = [[LTSimpleManager alloc] initWithFrame:CGRectMake(0, NavBarHeight, self.view.bounds.size.width, ScreenHeight - NavBarHeight - TabBarHeight) viewControllers:self.viewControllers titles:self.titles currentViewController:self layout:self.layout];
    
    /* 设置代理 监听滚动 */
    _managerView.delegate = self;
    
    /* 设置悬停位置 */
    //        _managerView.hoverY = 64;
    
    /* 点击切换滚动过程动画 */
    //        _managerView.isClickScrollAnimation = YES;
    
    /* 代码设置滚动到第几个位置 */
    //        [_managerView scrollToIndexWithIndex:self.viewControllers.count - 1];
    
  }
  return _managerView;
}


- (void)viewDidLoad {
  [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [self setNavImage:[UIImage imageNamed:@"Home_BgImage"] titleColor:[UIColor whiteColor]];

  [self setStatusBarStyleWhite];
}

- (void)createFields {
  [super createFields];
  
  
}

- (void)createViews {
  [super createViews];
  
  [self.view addSubview:self.managerView];

  
}

- (void)createConfig {
  [super createConfig];
  
  
  __weak typeof(self) weakSelf = self;
  
  //配置headerView
  [self.managerView configHeaderView:^UIView * _Nullable{
    return [weakSelf setupHeaderView];
  }];
  
  //pageView点击事件
  [self.managerView didSelectIndexHandle:^(NSInteger index) {
    NSLog(@"点击了 -> %ld", index);
    
  }];
  
  //控制器刷新事件
  [self.managerView refreshTableViewHandle:^(UIScrollView * _Nonnull scrollView, NSInteger index) {
    __weak typeof(scrollView) weakScrollView = scrollView;
    NSLog(@"刷新");
    //    scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
    //      __strong typeof(weakScrollView) strongScrollView = weakScrollView;
    //      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //        NSLog(@"对应控制器的刷新自己玩吧，这里就不做处理了🙂-----%ld", index);
    //        [strongScrollView.mj_header endRefreshing];
    //      });
    //    }];
    
  }];

}

#pragma mark - LTSimpleScrollViewDelegate

-(void)tapGesture:(UITapGestureRecognizer *)gesture {
  NSLog(@"tapGesture");
}

-(void)glt_scrollViewDidScroll:(UIScrollView *)scrollView {
  NSLog(@"---> %lf", scrollView.contentOffset.y);
}


@end

